#define RED_GPIO_OUT (unsigned int *)0xc001a000
#define RED_GPIO_OUTENB (unsigned int *)0xc001a004
#define RED_GPIO_ALT0 (unsigned int *)0xc001a024


#define GREEN_GPIO_OUT (unsigned int *)0xc001e000
#define GREEN_GPIO_OUTENB (unsigned int *)0xc001e004
#define GREEN_GPIO_ALT0 (unsigned int *)0xc001e020


#define BLUE_GPIO_OUT (unsigned int *)0xc001b000
#define BLUE_GPIO_OUTENB (unsigned int *)0xc001b004
#define BLUE_GPIO_ALT0 (unsigned int *)0xc001b020

void delay_ms(unsigned int ms){
	int x,y;
	for(x=0;x<ms;x++){
		for(y=0;y<100;y++){
		}
	}
}

void led_init(void){
	*RED_GPIO_OUT &= ~(1<<28);
	*RED_GPIO_OUTENB |= (1<<28);
	*RED_GPIO_ALT0 &= ~(3<<24);

	
	*GREEN_GPIO_OUT &= ~(1<<13);
	*GREEN_GPIO_OUTENB |= (1<<13);
	*GREEN_GPIO_ALT0 &= ~(3<<26);


	*BLUE_GPIO_OUT &= ~(1<<12);
	*BLUE_GPIO_OUTENB |= (1<<12);
	*BLUE_GPIO_ALT0 &= ~(3<<24);
	*BLUE_GPIO_ALT0 |= (1<<25);
}

void red_breath(void){
	int on = 300;
	int off = 0;
	while(1){
		*RED_GPIO_OUT |= (1<<28);
		delay_ms(on);
		*RED_GPIO_OUT &= ~(1<<28);
		delay_ms(off);
		on--;
		off++;/*
		if(on == 0){
			while(off){
				*RED_GPIO_OUT |= (1<<28);
				delay_ms(on);
				*RED_GPIO_OUT &= ~(1<<28);
				delay_ms(off);
				on++;
				off--;
			}
			break;
		}*/
	}
}

void blue_breath(void){
	int on = 300;
	int off = 0;
	while(1){
		*BLUE_GPIO_OUT &= ~(1<<12);
		delay_ms(on);
		*BLUE_GPIO_OUT |= (1<<12);
		delay_ms(off);
		on--;
		off++;
		break;
		if(on == 0){
			while(off){
				*BLUE_GPIO_OUT &= ~(1<<12);
				delay_ms(on);
				*BLUE_GPIO_OUT |= (1<<12);
				delay_ms(off);
				on++;
				off--;
			}
			break;
		}
	}

}

void green_breath(void){
	int on = 300;
	int off = 0;
	while(1){
		*GREEN_GPIO_OUT |= (1<<13);
		delay_ms(on);
		*GREEN_GPIO_OUT &= ~(1<<13);
		delay_ms(off);
		on--;
		off++;
		break;
		
		if(on == 0){
			while(off){
				*GREEN_GPIO_OUT |= (1<<13);
				delay_ms(on);
				*GREEN_GPIO_OUT &= ~(1<<13);
				delay_ms(off);
				on++;
				off--;
			}
			break;
		}
	}

}

int main(int argc, const char *argv[])
{
	led_init();
	int ms = 1000;
	while(1){
		*RED_GPIO_OUT |= (1<<28);
		delay_ms(ms);
		*RED_GPIO_OUT &= ~(1<<28);
		delay_ms(ms);
		*GREEN_GPIO_OUT |= (1<<13);
		delay_ms(ms);
		*GREEN_GPIO_OUT &= ~(1<<13);
		delay_ms(ms);
		*BLUE_GPIO_OUT |= (1<<12);
		delay_ms(ms);
		*BLUE_GPIO_OUT &= ~(1<<12);
		delay_ms(ms);
	}
	return 0;
}
